<?php

/*
 * CopyRight  : (C)2012-2099 HaoTeam Inc.
 * Document   : User.php
 * Created on : 2021-1-27 17:30:19
 * Author     : Tiger <1192851302@qq.com>
 * Description: This is NOT a freeware, use is subject to license terms.
 *              这即使是一个免费软件,使用时也请遵守许可证条款,得到当时人书面许可.
 *              未经书面许可,不得翻版,翻版必究;版权归属 HaoTeam Inc;
 */

namespace app\admin\controller;

use app\Request;
use haoteam\service\UtilService;
use app\models\User as UserModel;
use app\models\UserGroup;

/**
 * 用户管理
 * Class User
 * Tiger <1192851302@qq.com> 2021-1-27 17:30:19
 */
class User {

    /**
     * 用户列表
     * @auth true
     * @menu true
     * @author Tiger <1192851302@qq.com>
     * @return type
     */
    public function index(Request $request) {
        $post = UtilService::postMore([
                    'search',
                    'user_group'
        ]);
        return app('json')->successful(UserModel::getList(array_filter($post)));
    }

    /**
     * 用户更新
     * @auth true
     * @author Tiger <1192851302@qq.com>
     * @return type
     */
    public function update(Request $request) {
        $post = UtilService::postMore([
                    'user_group',
                    'status',
                    'id'
        ]);
        $id = $post['id'];
        UserModel::update($post, compact('id'));
        return app('json')->successful('更新成功');
    }

    /**
     * 用户组列表
     * @auth true
     * @menu true
     * @author Tiger <1192851302@qq.com>
     * @return type
     */
    public function group(Request $request) {
        [$search, $type] = UtilService::postMore([
                    ['search', ''],
                    ['type', 'all']
                        ], $request, true);
        return app('json')->successful(UserGroup::getList(compact('search'), $type));
    }

}
